package com.lesama.method;
public class MethodDemo1 {
    // 定义方法
    public static int solve(int[] nums) {
        int n = nums.length;
        if(n == 1)  return nums[0];
        if(n == 2)  return Math.max(nums[0], nums[1]);
        int first = nums[0];
        int second = Math.max(nums[0], nums[1]);
        int dp = 0;
        for(int i = 2; i < n; i++) {
            dp = Math.max(first + nums[i], second);
            first = second;
            second = dp;
        }
        return dp;
    }
    public static void main(String[] args) {
        int[] nums = {1, 9, 4, 6, 7, 3, 8, 1};
        System.out.println(solve(nums)); // 调用
    }
}
